package com.lzh.persevere.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.lzh.persevere.common.R;
import com.lzh.persevere.common.ResultUtil;
import com.lzh.persevere.model.entity.FriendLink;
import com.lzh.persevere.model.qo.PageModelQO;
import com.lzh.persevere.service.FriendLinkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * 友链controller
 *
 * @author luzhiheng
 * @since 2025-07-07
 */
@Api(tags = "友链")
@RestController
@RequestMapping("/friendLink")
public class FriendLinkController {

    @Resource
    private FriendLinkService friendLinkService;

    @ApiOperation(value = "查询友链列表")
    @PostMapping("/findFriendLinkList")
    public R<List<FriendLink>> findFriendLinkList() {
        List<FriendLink> friendLinkList = friendLinkService.list(Wrappers.<FriendLink>lambdaQuery().eq(FriendLink::getStatus, 1).eq(FriendLink::getOpenFlag, 1));
        return ResultUtil.success(friendLinkList);
    }

    @ApiOperation(value = "分页查询友链列表")
    @PostMapping("/findFriendLinkPage")
    public R<Map<String, Object>> findFriendLinkPage(@Valid @RequestBody PageModelQO qo) {
        return ResultUtil.success(friendLinkService.findFriendLinkPage(qo));
    }

    @ApiOperation(value = "添加友链")
    @PostMapping("/addFriendLink")
    public R<Boolean> addFriendLink(@RequestBody FriendLink friendLink) {
        return ResultUtil.success(friendLinkService.save(friendLink));
    }

    @ApiOperation(value = "更新友链")
    @PostMapping("/updateFriendLink")
    public R<Boolean> updateFriendLink(@RequestBody FriendLink friendLink) {
        return ResultUtil.success(friendLinkService.updateById(friendLink));
    }
}
